// The Vue build version to load with the `import` command
// (runtime-only or standalone) has been set in webpack.base.conf with an alias.
import Vue from 'vue'
import App from './App'
import {store} from './store'
import router from './router'
import ElementUI from 'element-ui'
import echarts from 'echarts'
import 'babel-polyfill'
import moment from 'moment'
import CookieUtil from '@/utils/CookieUtil'
// import {getToken} from '@/utils/LocalDataUtil'
import VueCropper from 'vue-cropper'
import './assets/theme/index.css'
import './assets/my-theme.css'
import '@/assets/iconfont/iconfont.css'

// 时间格式化组件 http://momentjs.com/
Vue.prototype.$moment = moment
Vue.prototype.$echarts = echarts
Vue.use(ElementUI)
Vue.use(VueCropper)
Vue.config.productionTip = false
Vue.prototype.$moment = moment
router.beforeEach((to, from, next) => {
  if (to.matched.some(m => m.meta.auth)) {
    // let token = getToken()
    let token = CookieUtil.getToken()
    if (to.path === '/login') {
      next()
    } else {
      if (!token || token.trim() === '') {
        next({name: 'login', params: {error: ''}})
        store.dispatch('cleartAction')
      } else {
        next()
      }
    }
  } else {
    store.dispatch('cleartAction')
    next()
  }
})

/* eslint-disable no-new */
new Vue({
  el: '#app',
  router,
  store,
  components: { App },
  template: '<App/>'
})
